﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Security;

namespace ProjectSem3.Admin
{
    public partial class WebForm17 : System.Web.UI.Page
    {
        dataDataContext dcs = new dataDataContext();
        protected void Page_Load(object sender, EventArgs e)
        {
            Employee us = (Employee)Session["user"];
            if (!IsPostBack)
            {
                if (us != null && us.RoleEmID != 1)
                    Button1.Visible = false;
              
            }
        }
        protected void Button1_Click(object sender, EventArgs e)
        {
            var list = dcs.Customers;
            if (list.Where(c => c.Username.Equals(TextBoxUsername.Text)).ToList().Count == 0)
                if (list.Where(c => c.Email.Equals(TextBoxMail.Text)).ToList().Count == 0)
                {
                    Employee em = new Employee();
                    em.Username = this.TextBoxUsername.Text;
                    em.Password = FormsAuthentication.HashPasswordForStoringInConfigFile(this.TextBoxpassword.Text, "sha1");
                    em.FullName = this.TextBoxName.Text;
                    em.BirthDay = Convert.ToDateTime(this.TextBoxBirthday.Text);
                    em.Gender = Radio1.Checked ? Radio1.Checked : false;
                    em.Email = this.TextBoxMail.Text;
                    em.Address = this.TextBoxAddress.Text;
                    em.Phone = this.TextBoxPhone.Text;
                    em.Salary = Convert.ToDouble(this.TextBoxSalary.Text);
                    em.Status = Radio1.Checked ? Radio1.Checked : false;
                    em.RoleEmID = 2;
                    this.dcs.Employees.InsertOnSubmit(em);
                    this.dcs.SubmitChanges();
                    Response.Redirect("ListEmployee.aspx");
                }
                else
                    lblEmailMessage.Text = "this email is registed";
            else
                lbluserMessage.Text = "username is exists";
        }
    }
}